<!DOCTYPE html>
<html lang="en">
<head>

<title>Text View</title>
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<!-- <script type="text/javascript" src="js/ckeditor_classic/ckeditor.js"></script> -->
<link rel="stylesheet" href="js/kindeditor/themes/default/default.css" />
<script charset="utf-8" src="js/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="js/kindeditor/lang/zh-CN.js"></script>
<style type="text/css">
body {
    padding:0px;
    margin: 0px;
}

.ke-content {
	white-space:pre;
	font-size: 18px;
}

</style>
</head>
<body style="overflow: hidden;">

<script>

function htmlEscape(text) { 
  return text.replace(/[<>"&]/g, function(match, pos, originalText){
    switch(match){
    case "<": return "&lt;"; 
    case ">":return "&gt;";
    case "&":return "&amp;"; 
    case "\"":return "&quot;"; 
  } 
  }); 
}

function return2Br(str) { 
    return str.replace(/\r?\n/g,"<br />"); 
} 

function getQueryParam(variable) {
    var href = window.location.href;
    var query = href.substring(href.indexOf("?") + 1);
    var pos = query.indexOf('=');
    
    if(pos != -1) {
    	return query.substring(pos + 1);
    }
    return '';
}
$(document).ready(function () {
	var url = getQueryParam("path");
	url = decodeURI(url);
	console.log(url);
	//$('#imgHolder').html("<img id='naturalImg' src='"+ url + "'/>")
	var editor;
    KindEditor.ready(function(K) {
        editor = K.create('#content', {
            allowFileManager : true
        });
    });
	var appJson = "application/json";
    $.ajax({
       url: url,
       type: 'GET',
       contentType: appJson,
       dataType : "text",
       data: '',
       beforeSend : function(req) {

       },
        success:function(data){
        	//data = data.replace(/\r\n/g,"<br>")
        	//data = data.replace(/\n/g,"<br>");
        	//$('#mytextarea').text(data);
           
        	editor.text(data);
        	
        	/* ClassicEditor.create(document.querySelector( '#mytextarea' ), 
        	        {
        	        // toolbar: [ 'heading', '|', 'bold', 'italic', 'link' ]
        	        })
        	        .then( editor => {
        	        	console.log(editor)
        	            window.editor = editor;
        	            //window.editor.setData("<pre>" + data + "</pre>");
        	        } )
        	        .catch( err => {
        	            console.error( err.stack );
        	        } ); */  
        },
        error:function(data){
               alert("Fail");
        }
   }); 

});


</script>

    <!-- <textarea id="mytextarea" style="font-size: 18px; overflow-x: hidden " rows="28" cols="77">
    </textarea>
 -->
<textarea id="content" name="content" style="width:750px;height:495px;white-space:pre;font-size: 18px;visibility:hidden;">KindEditor</textarea>
<!-- <div id="mytextarea" style="white-space:pre;font-size: 18px">

</div> -->

</body>

</html>
